#include<bits/stdc++.h>
#define F(i,x,y) for(int i=(x);i<=(y);i++)
#define DF(i,x,y) for(int i=(x);i>=(y);i--)
#define SZ(x) (int(x.size())-1)
#define mid ((l+r)>>1)
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
bool chkmax(long long &x,long long y){return (x<y?x=y:0);}
bool chkmax(int &x,int y){return (x<y?x=y:0);}
int n,a[200010],ans,b[200010];
void calc()
{
	int A=0,B=0,s=0;
	F(i,1,n)
		if(b[i])
		{
			if(A==a[i])
				s+=A;
			else
				A=a[i];
		}
		else
		{
			if(B==a[i])
				s+=B;
			else
				B=a[i];
		}
	chkmax(ans,s);
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    cin>>T;
    while(T--)
    {
        cin>>n;
        int ma=0;
        ans=0;
        F(i,1,n)
        {
			scanf("%d",a+i);
			chkmax(ma,a[i]);
		}
		if(n<=15)
		{
			F(i,0,(1<<n)-1)
			{
				F(j,0,n-1)
					b[j+1]=(i&(1<<j));
				calc();
			}
		}
		cout<<ans<<endl;
    }
    return 0;
}
//woyaodaqiu!!!
